package Ppackage;

public class Consumer implements Runnable
{
    private Buffer buffer;

    public Consumer(Buffer buffer)
    {
        this.buffer = buffer;
    }

    public void run()
    {
        while (true)
        {
            try
            {
                buffer.consume();
                Thread.sleep((int) (Math.random() * 1000)); // 模拟消费时间
            }
            catch (InterruptedException e)
            {
                Thread.currentThread().interrupt();
            }
        }
    }
}
